package jdbc01;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class jdbcDemo {
    public static void main(String[] args) throws Exception {
        //注册驱动
        Class.forName ( "com.mysql.cj.jdbc.Driver" );

        //获取连接对象
        Connection connection = DriverManager.getConnection (
                "jdbc:mysql://localhost:3306/bass?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true" ,
                "root" ,
                "password"
        );


        //准备sql语句
        String sql="insert into account(name,balance)values(?,?)";



        //发送sql语句到数据库中
        PreparedStatement preparedStatement = connection.prepareStatement ( sql );
        //给参数赋值
       preparedStatement.setString ( 1,"杨桑" );
       preparedStatement.setString ( 2,"1000" );

       //更新
        int i = preparedStatement.executeUpdate ( );
        System.out.println ("影响了"+i+"行" );
        //释放资源
        preparedStatement.close ();
        connection.close ();


    }
}
